package com.papper.common.utils.helper;

import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.StringTemplateResolver;

/**
 * @Author:Lajiao
 * @Date:2014年5月20日
 * @Time:下午5:58:45
 * @Description:系统模板解析
 */
public class ThymeleafHelp {
	private static ThymeleafHelp        instance             = null;
	private static SpringTemplateEngine springTemplateEngine = null;

	private ThymeleafHelp() {
	}

	public static synchronized ThymeleafHelp I() {
		if (instance == null) {
			instance = new ThymeleafHelp();
			instance.initPropertys();
		}
		return instance;
	}

	public void initPropertys() {
		springTemplateEngine = new SpringTemplateEngine();
		StringTemplateResolver stringTemplateResolver = new StringTemplateResolver();
		stringTemplateResolver.setCacheable(true);
		stringTemplateResolver.setTemplateMode(TemplateMode.HTML);
		springTemplateEngine.setTemplateResolver(stringTemplateResolver);
	}

	public String process(String template, Context context) {
		return springTemplateEngine.process(template, context);
	}
}
